package com.flex.showdoc4j.config;

import com.flex.showdoc4j.executor.*;
import com.flex.showdoc4j.executor.Wrapper;
import com.flex.showdoc4j.executor.interfaces.ClientExecutor;
import com.flex.showdoc4j.executor.interfaces.DocResolver;
import com.flex.showdoc4j.executor.interfaces.ParameterResolver;
import com.flex.showdoc4j.executor.interfaces.Render;
import com.flex.showdoc4j.model.ConfigModel;
import com.flex.showdoc4j.template.BeetlTemplateFactoryManage;
import com.flex.showdoc4j.template.TemplateFactory;
import org.springframework.context.ApplicationContext;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 配置文件
 *
 * @author ganlt<br>
 * @since 2019/06/26 15:01 <br>
 */
public class Configuration {
    /**
     * 注册对象
     */
    private Map<String, Object> mvcControlRegister = new ConcurrentHashMap<>();
    private Map<String, Object> mvcControlBeanRegister = new ConcurrentHashMap<>();
    /**
     * 模板引擎
     */
    private TemplateFactory templateFactory = new BeetlTemplateFactoryManage();
    /**
     * 对象包装器
     */
    private List<Wrapper> wrappers = new ArrayList<>();
    /**
     * 文档解析器
     */
    private DocResolver docResolver = new SimpleDocResolver(this);
    /**
     * 执行器
     */
    private ClientExecutor clientExecutor = new JvmClientExecutor();
   // private ClientExecutor clientExecutor = new HttpClientExecutor();
    /**
     * 渲染器
     */
    private Render render = new DocRender();
    /**
     * spring 上下文
     */
    private ApplicationContext applicationContext;
    /**
     * 基础配置参数
     */
    private ConfigModel configModel;

    private ParameterResolver parameterResolver = new ParameterResolverMapping();


    public Object getControl(String info) {
        return mvcControlRegister.get(info);
    }

    public void addControl(String info, Object control) {
        mvcControlRegister.putIfAbsent(info, control);
    }

    public Object getControlBean(String info) {
        return mvcControlBeanRegister.get(info);
    }

    public void addControlBean(String info, Object controlBean) {
        mvcControlBeanRegister.putIfAbsent(info, controlBean);
    }


    public ConfigModel getConfigModel() {
        return configModel;
    }

    public void setConfigModel(ConfigModel configModel) {
        this.configModel = configModel;
    }

    public List<Wrapper> getWrappers() {
        return wrappers;
    }

    public void setWrappers(List<Wrapper> wrappers) {
        this.wrappers = wrappers;
    }

    public DocResolver getDocResolver() {
        return docResolver;
    }

    public Render getRender() {
        return render;
    }

    public Map<String, Object> getMvcControlRegister() {
        return mvcControlRegister;
    }

    public TemplateFactory getTemplateFactory() {
        return templateFactory;
    }

    public ClientExecutor getClientExecutor() {
        return clientExecutor;
    }

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public ParameterResolver getParameterResolver() {
        return parameterResolver;
    }


    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }
}
